package com.yanqu.road.server.cmd.player;

import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.OldPlayerReturnProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/12/8 14:16
 */
@Cmd(code = CrossProtocol.C_CROSS_BIND_RETURN_ROLE, desc = "绑定回归角色")
public class CrossBindRoleCmd extends CrossCommand {
    private long bindServerId;
    private long bindUserId;
    private String oriOpenId;
    private PlayerProto.PlayerBaseTempMsg oriUserInfo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.BindReturnRoleReqCrossMsg msg = OldPlayerReturnProto.BindReturnRoleReqCrossMsg.parseFrom(packet.getBytes());
        bindServerId = msg.getServerId();
        bindUserId = msg.getUserId();
        oriOpenId = msg.getOriOpenId();
        oriUserInfo = msg.getOriUserInfo();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.BindReturnRoleCrossReqMsg.Builder reqMsg = OldPlayerReturnProto.BindReturnRoleCrossReqMsg.newBuilder();
        reqMsg.setOriServerId(serverId);
        reqMsg.setOriUserId(packet.getPlayerId());
        reqMsg.setOriUserInfo(oriUserInfo);
        reqMsg.setOriOpenId(oriOpenId);
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_BIND_RETURN_ROLE, reqMsg);
        MessageHelper.sendPacket(bindServerId, bindUserId, message);
    }

    @Override
    public void sendData() {

    }
}
